package com.qysoft.modules.xxwh.action;


import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.plugin.ehcache.CacheKit;
import com.qysoft.modules.common.contants.Contants;
import com.qysoft.modules.xxwh.service.JSGLService;
import com.qysoft.rapid.actions.JsonResultInterceptor;
import com.qysoft.rapid.actions.RapidAction;
import com.qysoft.rapid.core.RapidDbConn;
import com.qysoft.rapid.core.RapidDbConnTx;
import com.qysoft.rapid.dao.mybatis.common.CommonDao;
import com.qysoft.rapid.domain.Bean;

import java.util.List;

@Before(JsonResultInterceptor.class)
public class JSGLAction extends RapidAction {

	@Clear(JsonResultInterceptor.class)
	public void index() throws Exception{
		bindCurrentRyxxToPage();
		renderJsp("jsgl.jsp");
	}

	
	@Before(RapidDbConnTx.class)
	public void saveJSXX() throws Exception{
		Bean jsxx = getBean();
		jsxx.set("QX_ORGID", getCurrentRyxx().getOrgid());
		jsxx.set("ID", "seq_privid.nextval");
		jsxx.set("EXTEND_FLAG", Contants.YES);
		jsxx.set("FLAG", Contants.YES);
		CommonDao.insertByXml("role_insert",jsxx);
	}
	
	@Before(RapidDbConnTx.class)
	public void delete() throws Exception{
		String jsid = getPara("id");
		JSGLService.delete(jsid);
	}
	
	@Before(RapidDbConn.class)
	public void queryJSXX() throws Exception{
		String jsid = getPara("jsid");
		Bean jsxx = JSGLService.queryJSXX(jsid);
		setJson(jsxx);
	}
	
	@Before(RapidDbConnTx.class)
	public void updateJSXX() throws Exception{
		Bean jsxx = getBean();
		JSGLService.updateJSXX(jsxx);
	}
	
	@Before(RapidDbConnTx.class)
	public void saveJsZy() throws Exception{
		String jsid = getPara("id");
		String zyids = getPara("zyids");
		JSGLService.saveJsZy(jsid, zyids);
		//重置所有人授权的资源缓存
		CacheKit.removeAll("permissions");
	}
	
	@Before(RapidDbConn.class)
	public void queryJsForTree() throws Exception{
		List<Bean> jsList = JSGLService.queryJsForTree(getPara("id"));
		setJson(jsList);
	}
}
